package com.utils.messageFactory;

import com.entity.Customer;
import com.entity.Food;
import com.entity.Setmeal;
import com.utils.MailHtmlUtils;
import com.vo.MailUser;


public class CustomerMessageFactory implements MakeMessage{

    public String[] getMessage(MailUser mailUser, String opDeatil){
        Customer customer = (Customer)mailUser;
        StringBuilder mailMessage = new StringBuilder();
        String subject = null;
        switch (opDeatil){
            case "reg":
                mailMessage.append("<html>");
                mailMessage.append("亲爱的会员"+customer.getCname()+":<br>");
                mailMessage.append("注册成功");
                subject = "亲爱的会员"+customer.getCname() + "注册XX网站成功";
                break;
            case "addOrder":
                mailMessage.append("亲爱的会员"+customer.getCname()+":<br>");
                mailMessage.append("订购套餐成功,购买");
                Setmeal setmeal = customer.getSetmeal();
                mailMessage.append(setmeal.getDid()+" " + setmeal.getSmdesc());
                mailMessage.append("<table><tr><th>食物名称</th><th>食物价格</th></tr>");
                setmeal.getSetmealFoods().forEach(setmealFood -> {
                    Food food = setmealFood.getFood();

                    mailMessage.append("<tr><td>"+food.getFname()+"&nbsp;&nbsp;</td><td>"+food.getFdesc()+"</td></tr>");
                });
                mailMessage.append("");
                subject = "亲爱的会员"+customer.getCname() + "您的订单已下单成功";
                break;
            case "cancelOrder": break;
            case "timeout": break;
            default:break;
        }
        String [] mail = new String[2];
        mail[0] = subject;
        mail[1] = MailHtmlUtils.initHtml(mailMessage.toString());
        return mail;
    }
}
